#include<bits/stdc++.h>
#define int long long
using namespace std;
inline int read(){
	int x=0;bool f=0;char ch=getchar();
	while(ch<'0'||ch>'9')f^=(ch=='-'),ch=getchar();
	while('0'<=ch&&ch<='9')x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
	return f?-x:x;
}
int T;
inline int ksm(int a,int k){
	int res=1;
	for(;k;k>>=1,a=a*a)
		if(k&1)res=res*a;
	return res;
}
inline void solve(){
	int A=read(),B=read(),C=read(),ans=0;
	for(int i=1;i<=A;i++)
		for(int j=1;j<=B;j++)
			for(int k=1;k<=C;k++)
				if(ksm(j,i)==ksm(i,k))ans++;
	printf("%lld\n",ans);
}
signed main(){
	freopen("alien.in","r",stdin);
	freopen("alien.out","w",stdout);
	T=read();
	while(T--)solve();
	return 0;
}

